import { reqC1,reqC2,reqC3 } from "@/api/product/attr";
import { defineStore } from "pinia";
import type {CategoryState} from '@/store/modules/types/types'
import type {CategoryResponseData} from '@/api/product/attr/type'
const useCategoryStore = defineStore('Category',{
    state:():CategoryState=>{
        return{
            c1Arr:[],
            c1Id:'',
            c2Arr:[],
            c2Id:'',
            c3Arr:[],
            c3Id:'',
        }
    },
    actions:{
        //一级分类
       async getC1(){
            let res:CategoryResponseData = await reqC1()
            if(res.code == 200){
                this.c1Arr = res.data
            }
        },
        //二级分类
        async getC2(){
            let res:CategoryResponseData = await reqC2(this.c1Id)
            if(res.code == 200){
                this.c2Arr = res.data
            }
        },
        //三级分类
        async getC3(){
            let res:CategoryResponseData = await reqC3(this.c2Id)
            if(res.code == 200){
                this.c3Arr = res.data
            }
        }
    }
})
export default useCategoryStore